package com.googlecode.erebos.client;

import com.sun.sgs.client.simple.SimpleClientListener;
import com.sun.sgs.client.ClientChannelListener;
import com.sun.sgs.client.ClientChannel;

import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.PasswordAuthentication;
import java.nio.ByteBuffer;

/**
 * The MIT License
 * <p/>
 * Copyright (c) 2009 Malachi de AElfweald (malachid@gmail.com)
 * <p/>
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * <p/>
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * <p/>
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
public class ErebosClient
extends JFrame
implements SimpleClientListener, ActionListener
{
    /** The version of the serialized form of this class. */
    private static final long serialVersionUID = 1L;

    /** The name of the host property. */
    public static final String HOST_PROPERTY = "tutorial.host";

    /** The default hostname. */
    public static final String DEFAULT_HOST = "localhost";

    /** The name of the port property. */
    public static final String PORT_PROPERTY = "tutorial.port";

    /** The default port. */
    public static final String DEFAULT_PORT = "1139";

    /** The message encoding. */
    public static final String MESSAGE_CHARSET = "UTF-8";

    /**
     * Requests a login credential for the client associated with this
     * listener.
     *
     * @return a login credential for the client
     */
    public PasswordAuthentication getPasswordAuthentication() {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    /**
     * Notifies this listener that a session has been established with the
     * server as a result of a successful login.
     */
    public void loggedIn() {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    /**
     * Notifies this listener that a session could not be established with
     * the server due to some failure logging in such as failure to verify
     * a login credential.
     *
     * @param reason a description of the failure
     */
    public void loginFailed(String reason) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    /**
     * Notifies this listener that its associated client has joined the
     * specified {@code channel}, and returns a non-{@code null}
     * {@link com.sun.sgs.client.ClientChannelListener} for that channel.
     * <p/>
     * When a message is received on the specified channel, the returned
     * listener's {@link com.sun.sgs.client.ClientChannelListener#receivedMessage
     * receivedMessage} method is invoked with the specified channel and
     * the message.  The returned listener <i>is</i> notified of messages
     * that its client sends on the specified channel; that is, a sender
     * receives its own broadcasts.
     * <p/>
     * When the client associated with this server session leaves the
     * specified channel, the returned listener's {@link
     * com.sun.sgs.client.ClientChannelListener#leftChannel leftChannel} method is invoked with
     * the specified channel.
     *
     * @param channel a channel
     * @return a non-{@code null} listener for the specified channel
     */
    public ClientChannelListener joinedChannel(ClientChannel channel) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    /**
     * Notifies this listener that the specified message was sent by the
     * server.
     *
     * @param message a read-only {@link java.nio.ByteBuffer} containing the message
     */
    public void receivedMessage(ByteBuffer message) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    /**
     * Notifies this listener that its associated server session is in the
     * process of reconnecting with the server.
     * <p/>
     * If a connection can be re-established with the server in a timely
     * manner, this listener's {@link #reconnected reconnected} method will
     * be invoked. Otherwise, if a connection cannot be re-established, this
     * listener's {@code disconnected} method will be invoked with
     * {@code false} indicating that the associated session is
     * disconnected from the server and the client must log in again.
     */
    public void reconnecting() {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    /**
     * Notifies this listener whether the associated server session is
     * successfully reconnected.
     */
    public void reconnected() {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    /**
     * Notifies this listener that the associated server session is
     * disconnected.
     * <p/>
     * <p>If {@code graceful} is {@code true}, the disconnection
     * was due to the associated client gracefully logging out; otherwise,
     * the disconnection was due to other circumstances, such as forced
     * disconnection.
     * <p/>
     * <p>Before this method is invoked, it is guaranteed that the listeners
     * of all {@code ClientChannel}s with this session as a member will
     * have their {@link com.sun.sgs.client.ClientChannelListener#leftChannel leftChannel}
     * methods invoked.
     *
     * @param graceful {@code true} if disconnection was due to the
     *                 associated client gracefully logging out, and
     *                 {@code false} otherwise
     * @param reason   a string indicating the reason this session was
     *                 disconnected, or {@code null} if no reason was provided
     */
    public void disconnected(boolean graceful, String reason) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    /**
     * Invoked when an action occurs.
     */
    public void actionPerformed(ActionEvent e) {
        //To change body of implemented methods use File | Settings | File Templates.
    }
}
